import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { NativeProvider } from '../../providers/native/native';
import { Global } from '../../common/global';

/**
 * Generated class for the SettingPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-setting',
  templateUrl: 'setting.html',
})
export class SettingPage {

  address: string;
  constructor(public navCtrl: NavController, public navParams: NavParams, public uiservice: NativeProvider) {
    this.address = localStorage.getItem("address");
    Global.base_url = this.address;
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad ServerSettingPage');
  }
  savesetting() {
    if (this.address == null || this.address == '') {
      alert("服务器地址为空!");
      return;
    }
    localStorage.setItem("address", this.address);
    let serverAddress =  this.address.substr(0,this.address.substr(0,this.address.lastIndexOf("/")).lastIndexOf("/"))+"/";
    localStorage.setItem("serverAddress", serverAddress);
    Global.base_url = this.address;
    this.uiservice.showToast("保存成功！");
    this.navCtrl.pop();

  }

}
